function t(t, a, e) {
    return a in t ? Object.defineProperty(t, a, {
        value: e,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : t[a] = e, t;
}

var a;

Page({
    data: (a = {
        mch_id: 0,
        id: 0,//商品id
        postageIndex: -1,
        height: 0,
        beSubmit: !1,
        form: {},
        forehead: -1,
        page_loading: !1,
        unit: "件",
        iphone_x: !1,
        modal: !1,
        error: !1,
        set_cat: !1,
        set_link: !1,
        set_mch_cat: !1,
        set_postage: !1,
        set_service: !1,
        confine: !1,
        goods_card: [],
        img: {},
        cat: [],
        links: [],
        card: [],
        goods:[],
        is_detail:'',
        beMove: !1,
        service: [],
        postage: [],
        actions: [ {
            name: "我知道啦",
            color: "#446dfd"
        } ],
        action: [ {
            name: "取消",
            color: "#666666"
        }, {
            name: "确认",
            color: "#446dfd",
            loading: !1
        } ],
        beCat: [ {
            label: "未选择"
        } ],
        beMchCat: [{
            label: "未选择"
        }],
        beChooseCat:[{
            label: "未选择"
        }],
        isChooseCat: [ "未选择" ],
        p_id: 0,
        s_id: 0,
        choose_cat_name: '',
        choose_cat_arr:[],
        choose_link_arr:[],
        choose_link_name:'',
        cat_name: '',
        cat_sort: '',
        bePostage: "",
        beService: [],
        in_cat: "",
        newIndex: "0",
        index: "0",
        mch_cat: [],
        in_mch_cat: "",
    }, t(a, "form", {}), t(a, "attr", []), t(a, "have_children", !1), t(a, "disabled", !0), 
    t(a, "hidden", !0), t(a, "flag", !1), t(a, "x", 0), t(a, "y", 0), t(a, "elements", []), 
    t(a, "img_src", ""), a),
    touchm: function(t) {
        if (this.data.flag) {
            var a = t.touches[0].pageX, e = t.touches[0].pageY;
            this.setData({
                x: a - 60,
                y: e - 129
            });
        }
    },
    name: function(t) {
        var a = this.data.form;
        a.name = t.detail.value, this.setData({
            form: a
        });
    },
    sort: function(t) {
        var a = this.data.form;
        a.sort = t.detail.value, this.setData({
            form: a
        });
    },
    confineSwitch: function() {
        var a = this.data.form;
        var conf = this.data.confine;
        if(conf){
            a.is_show = 2;
        }else{
            a.is_show = 1;
        }
        this.setData({
            confine: !this.data.confine,
            form: a
        });
    },
    onLoad: function(t) {
        var a = this;
      getApp().page.onLoad(this, t);
      if (t.mch_id) {
          this.setData({
              mch_id: t.mch_id
          });
      }
      //商品id
      if (t.id) {
        this.setData({
            id: t.id
        });
        wx.setNavigationBarTitle({
          title: '分类编辑',
        })
      }
        getApp().core.getSystemInfo({
            success: function(t) {
                var e = t.windowHeight * (750 / t.windowWidth);
                a.setData({
                    height: e
                });
            }
        }), getApp().device().indexOf("iphone_x") > -1 && this.setData({
            iphone_x: !0
        }), this.getCat(),this.getLink(), this.data.mch_id > 0 && this.getMchCat();
        if (t.id) {
            //分类编辑
            getApp().request({
                url: getApp().api.admin.cat.edit,
                data: {id: a.data.id},
                method: "get",
                success: function (t) {
                    if (0 == t.code) {
                        var e = t.data,
                        i = a.data.img;
                        i.tubiao = {
                            pic_url: e.pic_url
                        };
                        i.datu = {
                            pic_url: e.big_pic_url
                        };
                        i.guanggao = {
                            pic_url: e.advert_pic
                        };
                        //分类
                        var cat_arr = a.data.cat;
                        for (var key in cat_arr) {
                            if(cat_arr[key].id == e.parent_id){
                                a.setData({
                                    in_cat: cat_arr[key].name
                                });
                            }
                        }
                        //广告链接
                        var links_arr = a.data.links;
                        for (var key in links_arr) {
                            if(links_arr[key].link == e.advert_url){
                                a.setData({
                                    in_link: links_arr[key].name
                                });
                            }
                        }
                        //显示、隐藏
                        if(e.is_show == 1){
                            var confine_val = !0;
                        }else if(e.is_show == 2){
                            var confine_val = !1;
                        }
                        //默认form表单值
                        var form_val = a.data.form;
                        form_val.choose_cat_id = e.parent_id;
                        form_val.name = e.name;
                        form_val.sort = e.sort;
                        form_val.pic_url = e.pic_url;
                        form_val.big_pic_url = e.big_pic_url;
                        form_val.advert_pic = e.advert_pic;
                        form_val.choose_link_value = e.advert_url;
                        form_val.is_show = e.is_show;

                        a.setData({
                            cat_name: e.name,
                            cat_sort: e.sort,
                            img: i,
                            confine: confine_val,
                            form: form_val
                        });
                    }
                }
            });
        }
    },
    bindChange: function(t) {
        var that = this;
        var a = t.detail.value;
        var choose_cat_name = '';
        var choose_cat_array = [];

        var cat_arr = that.data.cat;
        choose_cat_name = cat_arr[a[0]]['name'];
        if(choose_cat_name.indexOf('--') > -1){
            choose_cat_name = choose_cat_name.replace("--","");
        }
        choose_cat_array = cat_arr[a[0]];
        that.setData({
            newIndex: a[0],
            p_id: a[0],
            s_id: a[1],
            choose_cat_name: choose_cat_name,
            choose_cat_arr: choose_cat_array
        });
    },
    bindLinkChange: function(t) {
        var that = this;
        var a = t.detail.value;
        var choose_link_name = '';
        var choose_link_array = [];
        var cat_arr = that.data.links;
        choose_link_name = cat_arr[a[0]]['name'];
        choose_link_array = cat_arr[a[0]];
        that.setData({
            newIndex: a[0],
            p_id: a[0],
            s_id: a[1],
            choose_link_name: choose_link_name,
            choose_link_arr: choose_link_array
        });
    },
    close: function() {
        this.setData({
            modal: !this.data.modal,
            set_card: !1,
            set_cat: !1,
            set_mch_cat: !1,
            set_service: !1,
            set_postage: !1
        });
    },
    add_img: function(q){
        var t = this;
        var uptype = q.currentTarget.dataset.uptype;
        getApp().core.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(a) {
                var e = a.tempFilePaths, i = t.data.img;
                e.forEach(function(a, s) {
                    getApp().core.showLoading({
                        type: "loading"
                    }), getApp().core.uploadFile({
                        url: getApp().api.default.upload_image,
                        filePath: a,
                        name: "image",
                        success: function(a) {
                          getApp().core.hideLoading()
                            var r = JSON.parse(a.data);
                            i[uptype] = {
                                pic_url: r.data.url,
                                id: r.data.id
                            };
                            if(0 == r.code){
                                var a = t.data.form;
                                if(uptype == 'tubiao'){
                                    a.pic_url = r.data.url;
                                }else if(uptype == 'datu'){
                                    a.big_pic_url = r.data.url;
                                }else if(uptype == 'guanggao'){
                                    a.advert_pic = r.data.url;
                                }
                                t.setData({
                                    img: i,
                                    form: a
                                })
                            }
                            s == e.length - 1;
                        }
                    });
                });
            }
        });
    },
    chooseLink: function(t) {
        0 == this.data.links.length ? this.setData({
            modal: !0,
            set_link: !1
        }) : this.setData({
            choose_pick: this.data.links,
            choose_cat: !0,
            dialog: !0,
            set_link: !0,
            in_link: null,
            index: 0,
            have_children: !1,
            beCat: [ {
                label: "未选择"
            } ],
            isChooseCat: [ "未选择" ]
        });
    },
    chooseCat: function(t) {
        0 == this.data.cat.length ? this.setData({
            modal: !0,
            set_cat: !0
        }) : this.setData({
            choose_list: this.data.cat,
            choose_cat: !0,
            dialog: !0,
            set_cat: !0,
            in_cat: null,
            index: 0,
            have_children: !1,
            beCat: [ {
                label: "无"
            } ],
            isChooseCat: [ "无" ]
        });
    },
    chooseMchCat: function () {
        0 == this.data.mch_cat.length ? this.setData({
            modal: !0,
            set_mch_cat: !0
        }) : this.setData({
            choose_list: this.data.mch_cat,
            dialog: !0,
            set_mch_cat: !0,
            in_mch_cat: null,
            index: 0,
            have_children: !1,
            beMchCat: [{
                label: "未选择"
            }],
            isChooseCat: ["未选择"]
        });
    },
    choose_link: function() {
        var that = this;
        var a = that.data.form;
        a.choose_link_value = that.data.choose_link_arr.link;
        if(that.data.choose_cat){
            that.setData({
                in_link: that.data.choose_link_name,
                //choose_cat_id: that.data.choose_cat_arr.id,
                dialog: !1,
                set_link: !1,
                form: a
            });
        }
        return false;
    },
    choose_cat: function() {
        var that = this;
        var a = that.data.form;
        a.choose_cat_id = that.data.choose_cat_arr.id;
        if(that.data.choose_cat){
            that.setData({
                in_cat: that.data.choose_cat_name,
                //choose_cat_id: that.data.choose_cat_arr.id,
                dialog: !1,
                set_cat: !1,
                form: a
            });
        }
        return false;
    },
    choose_mch_cat: function () {
        var that = this;
        var choose_cat_arr_array = [that.data.choose_cat_arr];
        that.setData({
            beChooseCat: choose_cat_arr_array
        });
        var chs = this.data.beChooseCat;

        var t = this.data.beMchCat, a = !1, e = this.data.mch_cat[this.data.newIndex], i = this.data.index;
        if (this.data.have_children && (e = t[i - 1].children[this.data.newIndex - 1]),
            t[i] = e, this.setData({
                choose_list: []
            }), i++ , e) {
            // 商品分类选择 begin 
            if(that.data.choose_cat){
                t = chs;
                that.setData({
                    in_cat: that.data.choose_cat_name,
                    dialog: !1,
                    set_cat: !1
                });
            }else{
                var s = [];
                if (t.forEach(function (t, a) {
                    s.push(t.name);
                }), s.push("未选择"), this.setData({
                    isChooseCat: s
                }), e.children) {
                    var r = [];
                    r[0] = {
                        label: "不选择"
                    }, e.children.forEach(function (t) {
                        r.push(t);
                    }), a = !0, this.setData({
                        choose_list: r
                    });
                } else {
                    var o = void 0;
                    t.forEach(function (t, a) {
                        t.name.length > 5 && (t.name = t.name.slice(0, 4) + "..."), 0 == a ? o = t.name : o += "/" + t.name;
                    }), this.setData({
                        in_mch_cat: o,
                        dialog: !1,
                        set_mch_cat: !1
                    });
                }
            }
        } else {
            t.pop();
            var n = void 0;
            t.forEach(function (t, a) {
                0 == a ? n = t.label : n += "/" + t.label;
            }), this.setData({
                in_mch_cat: n,
                dialog: !1,
                set_mch_cat: !1
            });
        }
        this.setData({
            newIndex: "0",
            beMchCat: t,
            index: i,
            have_children: a
        });
    },
    toggle: function(t) {
        var a = t.currentTarget.dataset.status;
        if (2 == a) this.setData({
            choose_list: [],
            //links: [],
            dialog: !1,
            set_cat: !1,
            set_mch_cat: !1,
            set_postage: !1,
            set_link: !1
        }); else if (1 == a && this.data.set_postage) {
            var e = this.data.postage[this.data.newIndex];
            this.setData({
                bePostage: e,
                choose_list: [],
                //links: [],
                dialog: !1,
                set_mch_cat: !1,
                set_cat: !1,
                set_postage: !1
            });
        }
    },
    getCat: function() {
        var t = this;
        getApp().core.showLoading()
        getApp().request({
            url: getApp().api.admin.cat.get_cat,
            method: "get",
            success:function (a) {
              getApp().core.hideLoading()
              if ( 0 == a.code) {
                var e = a.data.list;
                t.setData({
                  cat: e
                });
              } else getApp().core.showToast({
                title: a.msg,
                icon: 'none'
              });
            },
            fale: function (t) {
              getApp().core.hideLoading()
              getApp().core.showToast({
                title: t.msg,
                icon: 'none'
              })
            }
        });
    },
    getMchCat: function () {
        var t = this;
        getApp().core.showLoading()
        getApp().request({
            url: getApp().api.admin.goods.get_mch_cat,
            data: {mch_id: t.data.mch_id},
            method: "get",
            success: function (a) {
                getApp().core.hideLoading()
                if (0 == a.code) {
                    var e = a.data.list;
                    t.setData({
                        mch_cat: e
                    });
                } else getApp().core.showToast({
                    title: a.msg,
                    icon: 'none'
                });
            },
            fale: function (t) {
                getApp().core.hideLoading()
                getApp().core.showToast({
                    title: t.msg,
                    icon: 'none'
                })
            }
        });
    },
    getLink: function() {
        var t = this;
        getApp().core.showLoading()
        getApp().request({
            url: getApp().api.admin.cat.pick_link,
            data: {
                mch_id: t.data.mch_id
            },
            method: "get",
            success:function (a) {
              getApp().core.hideLoading()
              if ( 0 == a.code) {
                var e = JSON.parse(a.data.list);
                t.setData({
                  links: e
                });
              } else getApp().core.showToast({
                title: a.msg,
                icon: 'none'
              });
            },
            fale: function (t) {
              getApp().core.hideLoading()
              getApp().core.showToast({
                title: t.msg,
                icon: 'none'
              })
            }
        });
    },
    choose: function(t) {
        var a = this.data.beService, e = t.currentTarget.dataset.detail;
        this.data.service.forEach(function(t) {
            t.id == e.id && (t.isChoose = !t.isChoose);
        }), this.setData({
            beService: a,
            service: this.data.service
        });
    },
    submit: function() {
        var a = this, e = a.data.form;
        if(e.choose_cat_id == undefined){
            e.choose_cat_id = 0;
            a.setData({
                form: e
            })
        }
        if(e.name == undefined){
            a.setData({
                error: "请填写分类名称"
            })
        }
        a.toSubmit();
    },
    toSubmit: function() {
        var that = this;
        getApp().core.showLoading();
        getApp().request({
            url: getApp().api.admin.cat.edit,
            data: {
                form: JSON.stringify(that.data.form),
                id:that.data.id > 0 ? that.data.id : ''
            },
            method: "post",
            success: function (t) {
              getApp().core.hideLoading(), 0 == t.code ? (getApp().core.showToast({
                title: t.msg,
                icon: 'none'
              }), that.cancel(), setTimeout(function () {
                    getApp().core.navigateTo({
                        url: "/app_admin/goods-cat/goods-cat"
                    });
              }, 500)) : getApp().core.showToast({
                title: t.msg,
                icon:'none'
              });
            },
            fale: function(t) {
              getApp().core.showToast({
                title: t.msg,
                icon: 'none'
              })
            }
        });
    },
    cancel: function() {
        this.setData({
            beSubmit: !1
        });
    },
    getError: function() {
        console.log('y');
        this.setData({
            error: !1
        });
    },
    onReady: function(t) {
        this.setData({
            page_loading: !1
        });
    },
    onShow: function() {
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});